const express = require('express');


var router = express.Router(),
    db = require('../lib/mysql');

var recommend = '';
var comment = '';
router.get('/',function(req,res,next){
    //查询推荐文章
    db.query( 'select * from article where a_recommend=1',function(err,data){
        if(err)
        {
            res.status(500).send('database error').end();
        }else{
            res.recommend = data;
            next();    
        }
    } );
});

router.get('/',function(req,res,next){
    //最新评论
    db.query('select * from comment order by c_add_time DESC limit 6',function(err,data){
        if(err)
        {
            res.status(500).send('database error').end();
        }else{
            res.comment = data;
            next();
        }         
    });
});

router.get('/',function(req,res){
    res.render('index.ejs',{comment:res.comment,recommend:res.recommend});
});


module.exports = router;